package fourfaith.com.ff_sl21_app.utils;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.view.inputmethod.InputMethodManager;

import java.util.Calendar;

/**
 * 常量
 *
 * @author administrator
 */
public class Constants {

    public static final boolean DEBUG = true;

    public static final String spFile = "cacheF";
    public static final String userKey = "userInfo";
    /**
     * 登录信息缓存文件
     */
    public static String _loginInfo = "login";
    /**
     * 视频参数配置缓存文件
     */
    public static String _videoConfig = "video";
    //视频参数默认值
    public static String videoIp = "127.0.0.1";
    public static String videoPort = "8080";

    /**
     * 接口地址
     */
    //public static String HOST = "http://192.168.9.133:8250/"
   /* public static String HOST = "http://222.47.29.203:10000/";*/
//    public static String HOST = "http://222.215.99.199:9001/";
//    public static String HOST = "http://119.3.33.246:9117/";//文清提供
//    public static String HOST = "http://192.168.25.36:8080/";//文清本地
//    public static String HOST = "http://47.99.32.215:9117/";//原本的
    public static String HOST = "http://47.111.127.81:6800/";//博意达
//    public static String HOST = "http://180.97.90.88:6662/";//20210204定制
    public static String apiUrl = "api";
    public static String address = HOST + apiUrl;


    /**
     * 通信中心地址 test
     */
/*    public static final String centerUrl =  "http://222.47.29.203:9018/api?protocol=";*/
      public static final String centerUrl =  "http://222.215.99.199:9003/api?protocol=";

    /**
     * 登录
     */
    public static final String login = address + "/user/login";
    /**
     * 修改密码
     */
    public static final String changePwd = address + "/user/changePwd";
    /**
     * 主页数据
     */
    public static final String homeData = address + "/home/getHomeData";
    /**
     * 实时数据
     */
    public static final String readtimeData = address + "/factor/getByUserId";
    /**
     * 获取设备最新要素数据
     */
    public static final String readtimeDataByStcd = address + "/factor/getByStcd";
    /**
     * GET 带摄像头的设备最新图片列表
     */
    public static final String videoPhotoList = address + "/devicePhoto/getVideoAndPhotoList";

    /**
     * GET  设备最新的图片列表
     */
    public static final String allDevicePhotoList = address + "/devicePhoto/getPhotoList";

    /**
     * GET  单设备的图片列表
     */
    public static final String devicePhotoList = address + "/devicePhoto/getPhotoByStcd";

    /**
     * 查找设备信息
     */
    public static final String deviceInfo = address + "/device/getByStcd";

    /**
     * GET 查找所有设备列表
     */
    public static final String deviceList = address + "/device/getDeviceList";
    /**
     * GET /device/getAllFactorByStcd 查找设备详细报送类型
     */
    public static final String getAllFactorByStcd = address + "/device/getAllFactorByStcd";
    /**
     * GET 查找设备报送类型及对应编码
     */
    public static final String getFactorByStcd = address + "/device/getFactorByStcd";

    /**
     * GET  通知列表
     */
    public static final String announceList = address + "/announce/getAnnounceList";

    /**
     * POST  阅读通知
     */
    public static final String announceRead = address + "/announce/read";

    /**
     * GET  设备的历史要素列表
     */
    public static final String allFactorList = address + "/allFactor/getFactorList";

    /**
     * GET  设备的告警列表
     */
    public static final String alarmList = address + "/alarm/getAlarmList";

    /**
     * POST  处理报警
     */
    public static final String alarmSolved = address + "/alarm/solved";

    /**
     * POST  撤销处理
     */
    public static final String alarmSolvedCancel = address + "/alarm/solvedCancel";

    /**
    * GET  查找设备详细报送类型
    */
    public static final String allFactorByStcd =address + "/device/getAllFactorByStcd";

    /**
     * GET  设备要素的报表数据列表
     */
    public static final String reportList = address + "/report/getReportList";

    /**
     * GET  获取最新的app版本
     */
    public static final String versionInfo = address + "/app/getLastVer";

    public static final String FIRST_OPEN = "first_open";

    /********************和中心交互的标识符**************************/


    public static String readFactory="3A";//中心站查询遥测站指定要素实时数据

    public static String readVersonStatus="45";//查询软件版本

    public static String rtuRestart = "E2";//RTU远程重启62

    public static String readDistanceConfig = "41";//读取配置表

    public static String updateConfig = "40";//修改配置表

    public static String rtuUpgrade = "E1";//RTU远程升级61

    public static String readAlarmSetting = "43";//报警设定读取

    public static boolean isNotEmpty(String str) {
        boolean flag = true;
        if (str == null || str.equals("")) flag = false;
        return flag;
    }

    /**
     * 获取当前的登录用户的id
     */
    public static String getUserId() {
        SharedPreferences sharedPreferences = SLApplication.getContext().getSharedPreferences(Constants._loginInfo, Context.MODE_PRIVATE);
        String userId = sharedPreferences.getString("userId", "");
        return userId;
    }
    public static String getUserName() {
        SharedPreferences sharedPreferences = SLApplication.getContext().getSharedPreferences(Constants._loginInfo, Context.MODE_PRIVATE);
        String userName = sharedPreferences.getString("userName", "");
        return userName;
    }

    public static String getString(Object obj) {
        String r = "";
        if (obj != null) r = obj.toString();
        return r;
    }

    /**
     * 根据手机的分辨率从 dp 的单位 转成为 px(像素)
     */
    public static int dip2px(Context context, float dpValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }

    /**
     * 根据手机的分辨率从 px(像素) 的单位 转成为 dp
     */
    public static int px2dip(Context context, float pxValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (pxValue / scale + 0.5f);
    }

    public static void closeKeyBoard(Activity activity){
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(activity.getWindow().getDecorView().getWindowToken(), 0);
    }

    public static Calendar setMaxTimeForMonthDate(Calendar cal){
        cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE));
        return cal;
    }
    public static Calendar setMinTimeForMonthDate(Calendar cal){
        cal.set(Calendar.DATE, 1);
        return cal;
    }
}
